﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ControlTypeTemplateSelection.cs" company="None">
//   <Author>Adrian von Allmen, 2013</Author>
// </copyright>
// <summary>
//   Select proper template for dynamic data binding and control selection.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Filter_Misc
{
    using System.Windows;
    using System.Windows.Controls;

    using CrumbleLibrary;

    /// <summary>
    /// Select proper template for dynamic data binding and control selection
    /// </summary>
    public class ControlTypeTemplateSelection : DataTemplateSelector
    {
        /// <summary>
        /// Gets or sets the text box template.
        /// </summary>
        public DataTemplate TextBoxTemplate { private get; set; }

        /// <summary>
        /// Gets or sets the check box template.
        /// </summary>
        public DataTemplate CheckBoxTemplate { private get; set; }

        /// <summary>
        /// Gets or sets the list box template.
        /// </summary>
        public DataTemplate ListBoxTemplate { private get; set; }

        /// <summary>
        /// Gets or sets the combo box template.
        /// </summary>
        public DataTemplate ComboBoxTemplate { private get; set; }

        /// <summary>
        /// The select template.
        /// </summary>
        /// <param name="item"> The item. </param>
        /// <param name="container"> The container. </param>
        /// <returns> DataTemplate which should apply </returns>
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var filterItem = item as FilterItemDynamic;
            if (filterItem != null)
            {
                switch (filterItem.Type)
                {
                    case HelperLibrary.FilterType.CheckBox:
                        return this.CheckBoxTemplate;
                    case HelperLibrary.FilterType.Textbox:
                        return this.TextBoxTemplate;
                    case HelperLibrary.FilterType.ListBox:
                        return this.ListBoxTemplate;
                    case HelperLibrary.FilterType.ComboBox:
                        return this.ComboBoxTemplate;
                    default:
                        return base.SelectTemplate(item, container);
                }
            }

            return base.SelectTemplate(item, container);
        }
    }
}
